using System;

namespace Conusic
{
    internal sealed class StringComparerOnlyChars : StringComparer
    {
        public override int Compare(string x, string y)
        {
            int xPosition = 0;
            int yPosition = 0;
            while (xPosition < x.Length && yPosition < y.Length)
            {
                if (!Char.IsLetter(x[xPosition]))
                {
                    xPosition++;
                    continue;
                }
                if (!Char.IsLetter(y[yPosition]))
                {
                    yPosition++;
                    continue;
                }

                if (char.ToUpper(x[xPosition]) == char.ToUpper(y[yPosition]))
                {
                    xPosition++;
                    yPosition++;
                }
                else
                {
                    if (x[xPosition] < y[yPosition])
                        return -1;
                    else
                        return 1;
                }
            }

            while (xPosition < x.Length && !char.IsLetter(x[xPosition]))
                xPosition++;

            while (yPosition < y.Length && !char.IsLetter(y[yPosition]))
                yPosition++;

            if (xPosition == x.Length && yPosition == y.Length)
            {
                return 0;
            }
            else
            {
                if (xPosition == (x.Length + 1))
                {
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
        }

        public override
            bool Equals(string x, string y)
        {
            return this.Compare(x, y) == 0 ? true : false;
        }

        public override
            int GetHashCode(string obj)
        {
            throw new NotImplementedException();
        }
    }
}